import house from '@/components/longHouse.vue';
import noneList from '@/components/noneList.vue';
import MeScroll from 'mescroll.js';
import {Toast,MessageBox} from 'mint-ui';
export default {
  name:'orderList',
  data: () => ({
    noneCollect:false,
    mescroll: null,
		pdlist: [],
  }),
  components :{
    house,
    noneList,
  },
  methods: {
    // 失效房源提示
    delHouse(info) {
      let that = this;
      if(info.isDel==1){
        Toast("当前房源已失效");
      }else {
        if(info.state==2) {
          Toast("当前房源已出租");
        }else if(info.state==4){
          Toast("当前房源已转租");
        }else {
          that.$router.push({path: '/houseDetail', query: {
            houseId: info.houseId,
            lat:info.lat,
            lng:info.lng}});
        }
      }
    },
    // 获取临时密码
    getLockCode(index) {
      let that = this;
      let dataList = that.pdlist[index];
        // if (dataList.state==1) {  //待签约
        //   Toast('该房源还未签约，没有临时密码');
        // }else {
          // that.$router.push({path:'/temporaryLock',query:{houseId:dataList.houseId}})
        // }
        // 获取临时密码
        network.get(configUrl.TEMPORARYLOCK_URL,{houseId:dataList.houseId},function(res){
          console.log(res);
          MessageBox.alert(res.data.password,'临时密码');
        },function(err){
          console.log(err);
        });
    },
    // 地图导航
    toMap(lng,lat,address,title){
      this.$router.push({path:'/aMap',query:{lng:lng,lat:lat,address:address,title:title}});
    },
    // 预约时间是否已过，为已完成，否则待看房
    orderTime(reservationTime){
      let today = new Date();
      if (reservationTime<Date.parse(today)) {
        return '已完成';
      }else {
        return '待看房';
      }
      console.log(today);
    },
    getListDataFromNet(pageNum,pageSize,successCallback,errorCallback) {

        this.$ajax.get(configUrl.MYRESERVATION_URL, {
					params: {
						currentPage: pageNum, //页码
						showCount: pageSize //每页长度
					}
				})
				.then((response) => {
          console.log(response);
					var data=response.data.dataList;
          if (pageNum==1) {
            if (data.length==0) {
              self.noneCollect = true;
            }else {
              self.noneCollect = false;
            }
          }
          successCallback&&successCallback(data);//成功回调
				})
				.catch((error) => {
					errorCallback&&errorCallback()//失败回调
				});
		},
    //上拉回调 page = {num:1, size:10}; num:当前页 ,默认从1开始; size:每页数据条数,默认10
		upCallback: function(page) {
			//联网加载数据
			var self = this;
			self.getListDataFromNet(page.num, page.size, function(curPageData) {
				//curPageData=[]; //打开本行注释,可演示列表无任何数据empty的配置

				//如果是第一页需手动制空列表 (代替clearId和clearEmptyId的配置)
				if(page.num == 1) self.pdlist = [];

				//更新列表数据
				self.pdlist = self.pdlist.concat(curPageData);

				//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
				//mescroll会根据传的参数,自动判断列表如果无任何数据,则提示空;列表无下一页数据,则提示无更多数据;
				console.log("page.num="+page.num+", page.size="+page.size+", curPageData.length="+curPageData.length+", self.pdlist.length==" + self.pdlist.length);
				//方法四 (不推荐),会存在一个小问题:比如列表共有20条数据,每页加载10条,共2页.如果只根据当前页的数据个数判断,则需翻到第三页才会知道无更多数据,如果传了hasNext,则翻到第二页即可显示无更多数据.
				self.mescroll.endSuccess(curPageData.length);

			}, function() {
				//联网失败的回调,隐藏下拉刷新和上拉加载的状态;
				self.mescroll.endErr();
			});
		},
    getReservationTime(index) {
      let that = this;
      let datalist = that.pdlist[index];
      let reservationTime = new Date(datalist.reservationTime);   //预约时间
      let month = (reservationTime.getMonth()+1) < 10 ? '0'+(reservationTime.getMonth()+1) : (reservationTime.getMonth()+1);   //月
      let day = reservationTime.getDate()<10? '0'+reservationTime.getDate() : reservationTime.getDate();      //日
      let weekday = reservationTime.getDay();   //星期
      let _time = reservationTime.getHours();   //小时
      let week = '';
      switch (weekday) {
        case 0:
          week = '周日';
          break;
        case 1:
          week = '周一';
          break;
        case 2:
          week = '周二';
          break;
        case 3:
          week = '周三';
          break;
        case 4:
          week = '周四';
          break;
        case 5:
          week = '周五';
          break;
        case 6:
          week = '周六';
          break;
        default:
          break;
      }
      return month+'.'+day+' '+week+' '+_time+':00';
      // console.log(_time);
    },
  },
  mounted() {
    //do something after mounting vue instance
    var self = this;
		self.mescroll = new MeScroll("mescroll", { //请至少在vue的mounted生命周期初始化mescroll,以确保您配置的id能够被找到
			up: {
				callback: self.upCallback, //上拉回调
				//以下参数可删除,不配置
				isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
				//page:{size:8}, //可配置每页8条数据,默认10
				toTop:{ //配置回到顶部按钮
					src : "../res/img/mescroll-totop.png", //默认滚动到1000px显示,可配置offset修改
					//html: null, //html标签内容,默认null; 如果同时设置了src,则优先取src
					//offset : 1000
				},
				empty:{ //配置列表无任何数据的提示
					warpId:"dataList",
					icon : require("@/assets/images/attention@2x.png") ,
						  	tip : "当前还未预约房源，快去预约吧~" ,
//						  	btntext : "去逛逛 >" ,
//						  	btnClick : function() {
//						  		alert("点击了去逛逛按钮");
//						  	}
				},
				//vue的案例请勿配置clearId和clearEmptyId,否则列表的数据模板会被清空
				//vue的案例请勿配置clearId和clearEmptyId,否则列表的数据模板会被清空
//						clearId: "dataList",
//						clearEmptyId: "dataList"
			}
		});
  }
}
